FROM ubuntu:ustc
SHELL ["/bin/bash", "-c"]
ARG U_NAME=jenkins
ARG U_ID=6002

ADD openjdk-21.0.1_linux-x64_bin.tar.gz /opt/env/jdk/
COPY jenkins.war /opt/env/jenkins/
COPY entrypoint.sh /entrypoint.sh

ENV RUN_JAVA_HOME=/opt/env/jdk/jdk-21.0.1
ENV JENKINS_HOME=/srv/jenkins
ENV JENKINS_MANAGE_PORT=8080
ENV JAVA_HOME=/opt/build_env/jdk
ENV MAVEN_HOME=/opt/build_env/maven
ENV M2_HOME=/opt/build_env/maven
ENV GRADLE_HOME=/opt/build_env/gradle
ENV GRADLE_USER_HOME=/opt/build_env/gradle_repository
ENV NODE_HOME=/opt/build_env/nodejs
ENV GO_ROOT=/opt/build_env/golang
ENV PYTHON_HOME=/opt/build_env/python

RUN groupadd ${U_NAME} -g ${U_ID}; \
useradd -u ${U_ID} -g ${U_ID} -d /home/${U_NAME} -m -s /sbin/nologin ${U_NAME}; \
mkdir -p /srv/jenkins/{data,logs}; chown -R ${U_NAME}:${U_NAME} /srv/jenkins; \
apt-get install -y libfreetype6 libfontconfig1 dos2unix; \
apt-get clean ; apt-get autoclean ; apt-get autoremove ; rm -rf /var/lib/apt/lists/* ; \
echo 'export PATH=${PATH}:${JAVA_HOME}/bin:${MAVEN_HOME}/bin:${GRADLE_HOME}/bin:${NODE_HOME}/bin:${GO_ROOT}/bin:${PYTHON_HOME}/bin;' > /etc/profile.d/02-local-env.sh ;\
mkdir -p /opt/build_env/maven_repository; mkdir -p /opt/build_env/gradle_repository; \
chmod og+rw /opt/build_env/maven_repository; chmod og+rw /opt/build_env/gradle_repository; \
dos2unix /entrypoint.sh; chmod +x /entrypoint.sh

EXPOSE 8080
EXPOSE 50000

VOLUME /srv/jenkins
VOLUME /opt/build_env/jdk
VOLUME /opt/build_env/maven
VOLUME /opt/build_env/maven_repository
VOLUME /opt/build_env/gradle
VOLUME /opt/build_env/gradle_repository
VOLUME /opt/build_env/nodejs
VOLUME /opt/build_env/golang
VOLUME /opt/build_env/python

USER ${U_NAME}

ENTRYPOINT ["/entrypoint.sh"]